package umacis.data.description;

import java.util.Vector;

import com.sun.lwuit.Component;
import com.sun.lwuit.util.Log;

import umacis.lwuitcomponent.property.Properties;
import umacis.lwuitcomponent.property.PropertyAssigner;



public class ComponentDescription {
	
	
	private String uniqueName = "";
	private String lwuitComponentClassName;
	protected Properties properties = new Properties();
	
	public ComponentDescription(String uniqueName) {
		this.setUniqueName(uniqueName);
	}
	
	public void build(Component cmp, Properties imposedProperties) {
		
		PropertyAssigner.getInstance().applyProperties(cmp, properties.defaultingTo(imposedProperties));
		
	}
	
	
	
	public String getLwuitComponentClassName() {
		return lwuitComponentClassName;
	}

	public Component createLwuitComponent(Properties imposedProperties) {
		try {
			Component cmp =(Component) Class.forName(lwuitComponentClassName).newInstance();
			PropertyAssigner.getInstance().applyProperties(cmp, properties.defaultingTo(imposedProperties));
			cmp.putClientProperty("Description", this);
			return cmp;
			
		} catch (InstantiationException e) {
			Log.p("InstantiationException" + e.getMessage(), Log.ERROR);
		} catch (IllegalAccessException e) {
			Log.p("IllegalAccessException" + e.getMessage(), Log.ERROR);
		} catch (ClassNotFoundException e) {
			Log.p("ClassNotFoundException" + e.getMessage(), Log.ERROR);
		}
		return null;
		
		
		
	}

	public void setUniqueName(String uniqueName) {
		this.uniqueName = uniqueName;
	}

	public String getUniqueName() {
		return uniqueName;
	}
	
}
